<?php
/**
 * Created by PhpStorm.
 * User: shaowei
 * Date: 2022/9/4
 * Time: 13:00
 */

namespace App\Tools;


use Illuminate\Support\Facades\Log;
use Ixudra\Curl\Facades\Curl;
use Ramsey\Uuid\Uuid;

class Shumei
{

    public function __construct(){

    }

    public function check($content) {
        $url = 'http://api-text-bj.fengkongcloud.com/v2/saas/anti_fraud/text';
        $data['accessKey'] = 'AcLmU94uW6svh8zTjsYM';
        $data['type'] = 'ZHIBO';
        $data['appId'] = 'default';
        $data['organization'] = 'zVl7MjUVneBOsAp9Kq0n';
        $data['data'] = [
            "text" => $content,
            "tokenId" => Uuid::uuid4()->toString()
        ];

        $ret_data = Curl::to($url)->withData($data)->asJson()->post();
        $ret_data = (array)$ret_data;

        //Log::info('shumeiCheck', $ret_data);

        if ($ret_data['code'] == 1100 && $ret_data['riskLevel'] && $ret_data['riskLevel'] == "PASS") {
            return $content;
        } else {
            $detail = json_decode($ret_data['detail'] ?? '{}', true);
            return $detail['filteredText'] ?? '';
        }
        return '';
    }

}